/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * pAddPriceInput.java
 *
 * Created on Mar 4, 2011, 4:06:32 PM
 */

package com.fa.supporters;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;

/**
 *
 * @author tatung
 */
public class pAddPriceInput extends javax.swing.JPanel {
    private boolean isOutPrice;
    /** Creates new form pAddPriceInput */
    public pAddPriceInput() {
        initComponents();

        this.dateChooser.setDate(Calendar.getInstance().getTime());
        SpinnerDateModel sm = new SpinnerDateModel(new Date(), null, null, Calendar.HOUR_OF_DAY);
        this.spnTime.setModel(sm);
        JSpinner.DateEditor de = new JSpinner.DateEditor(spnTime, "HH:mm");
        spnTime.setEditor(de);

        this.dateChooser.setDateFormatString("yyyy-MM-dd");
        Vector<String> productList = DbConnector.getProductList(false);
        this.cbxProductList.setModel(new DefaultComboBoxModel(productList));
        Vector<String> partnerList = DbConnector.getPartnerList();
        this.cbxPartnerList.setModel(new DefaultComboBoxModel(partnerList));
    }

    public void setIsOutPrice(boolean isOutPrice){
        this.isOutPrice = isOutPrice;
    }

    public boolean isOutPrice(){
        return isOutPrice;
    }

    public String getDateTimeString(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String ret = sdf.format(this.dateChooser.getDate());
        ret += " " + (new SimpleDateFormat("HH:mm")).format((Date)this.spnTime.getValue()) + ":00";
        JOptionPane.showMessageDialog(null, ret);
        return ret;
    }

    public String getProductName(){
        return (String)this.cbxProductList.getSelectedItem();
    }

    public String getPartnerName(){
        return (String)this.cbxPartnerList.getSelectedItem();
    }

    public float getPrice(){
        return Float.parseFloat(this.txtPrice.getText());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        dateChooser = new com.toedter.calendar.JDateChooser();
        jLabel4 = new javax.swing.JLabel();
        cbxProductList = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        cbxPartnerList = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        txtPrice = new javax.swing.JTextField();
        lblUnit = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        spnTime = new javax.swing.JSpinner();

        jLabel1.setText(org.openide.util.NbBundle.getMessage(pAddPriceInput.class, "pAddPriceInput.jLabel1.text")); // NOI18N

        jLabel4.setText(org.openide.util.NbBundle.getMessage(pAddPriceInput.class, "pAddPriceInput.jLabel4.text")); // NOI18N

        cbxProductList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel5.setText(org.openide.util.NbBundle.getMessage(pAddPriceInput.class, "pAddPriceInput.jLabel5.text")); // NOI18N

        cbxPartnerList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel6.setText(org.openide.util.NbBundle.getMessage(pAddPriceInput.class, "pAddPriceInput.jLabel6.text")); // NOI18N

        txtPrice.setText(org.openide.util.NbBundle.getMessage(pAddPriceInput.class, "pAddPriceInput.txtPrice.text")); // NOI18N

        lblUnit.setText(org.openide.util.NbBundle.getMessage(pAddPriceInput.class, "pAddPriceInput.lblUnit.text")); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "m", "y", "kg" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(dateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(spnTime, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(cbxPartnerList, 0, 224, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblUnit)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(cbxProductList, 0, 224, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(12, 12, 12))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(spnTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(dateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cbxProductList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cbxPartnerList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUnit)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbxPartnerList;
    private javax.swing.JComboBox cbxProductList;
    private com.toedter.calendar.JDateChooser dateChooser;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel lblUnit;
    private javax.swing.JSpinner spnTime;
    private javax.swing.JTextField txtPrice;
    // End of variables declaration//GEN-END:variables

}
